@extends('app')
@include('UEditor::head')
@section('content')
<ul class="nav nav-tabs">
    <li><a href="/admin/teaches/index">课程列表</a></li>
     <li class="active"><a href="#">新增课程</a></li>
</ul>
<form action="" id="teachesForm">
    <div class="panel panel-default mt20">
        <div class="table-responsive panel-body">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">课程名称</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" name="name" id="name" class="form-control" value="@if(!empty($result)){{$result->name}}@endif" />
                </div>
                <div class="clearfix"></div>
            </div> 
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">课程分类</label>
                <div class="col-sm-3 col-xs-12" id="parent">
                    <select name="type" class="form-control" id="type" onchange="getChilds('category',this.value,'parent')">
                        <option value="0">请选择分类</option>
                        @foreach($type as $tp)
                        <option value="{{ $tp->cat_id }}" @if(!empty($result)) @if(in_array($tp->cat_id,$categorys['id'])) selected @endif @endif>{{ $tp->cat_name }}</option>
                        @endforeach
                    </select>
                </div>
                @if(!empty($result))
                    @if($item != 5)
                    @foreach($categorys['list'] as $k=>$cglist)
                        <div class="col-sm-3 col-xs-12" id="child_{{$k-$item}}">
                            <select name="child_{{ $k-$item }}" class="form-control" id="child" onchange="getChilds(this.value,'child_{{ $k-$item }}')">
                        		<option value="0">请选择分类</option>
                        		@foreach($cglist as $cgl)
                        		<option value="{{ $cgl->cat_id }}" @if(in_array($cgl->cat_id,$categorys['id'])) selected @endif>{{ $cgl->cat_name }}</option>
                        		@endforeach
                        	</select>
                        </div>
                    @endforeach
                    @endif
                    @if($item ==5)
                    <div class="col-sm-3 col-xs-12" id="child_1"></div>
                    <div class="col-sm-3 col-xs-12" id="child_2"></div>
                    <div class="col-sm-3 col-xs-12" id="child_3"></div>
                    @elseif($item==4)
                    <div class="col-sm-3 col-xs-12" id="child_2"></div>
                    <div class="col-sm-3 col-xs-12" id="child_3"></div>
                    @elseif($item == 3)
                    <div class="col-sm-3 col-xs-12" id="child_3"></div>
                    @endif
                @else
                <div class="col-sm-3 col-xs-12" id="child_1"></div>
                <div class="col-sm-3 col-xs-12" id="child_2"></div>
                <div class="col-sm-3 col-xs-12" id="child_3"></div>
                @endif
                <div class="clearfix"></div>
            </div>  
            <div class="from-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">封面图片：</label>
                <div class="col-sm-9 col-xs-12">
                    <div class="input-group ">
                    	<input type="file" name="thumburl" id="thumburl" value="" class="form-control" autocomplete="off">
                    </div>
                     <div id="imgbox" class="dustbin">
                     @if(!empty($result))
                        @if(count($result->attachment)>0)
        	              <img src='{{$result->attachment->url}}'  width='90' height='60'>
        	              <input type='hidden' name='thumb' value='{{$result->attachment->aid}}'>
        	           @endif
        	         @endif
        	         
                     </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group mt10">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">课程简介：</label>
                <div class="col-sm-9 col-xs-12">
                    <script id="description" name="description"  style="width:100%;margin:0 auto;height:100px;" type="text/plain">
                    </script>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                 <label class="col-xs-12 col-sm-3 col-md-2 control-label">课程须知：</label>
                <div class="col-sm-9 col-xs-12">
                    <textarea rows="" class="form-control" cols="" name="notice">@if(!empty($result)) {{ $result->notice }} @endif</textarea>
                    <span class='help-block'>课程详情页面 头部 右边展示的小 tips 内容</span>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                 <label class="col-xs-12 col-sm-3 col-md-2 control-label">难易级别：</label>
                <div class="col-sm-9 col-xs-12">
                    <label class="radio-inline">
                      <input type="radio" name="level" value="0"  @if(!empty($result)) @if($result->level == 0) checked @endif @else checked @endif> 初级
                    </label>
                    <label class="radio-inline">
                      <input type="radio" name="level" value="1" @if(!empty($result)) @if($result->level == 1) checked @endif @endif> 中级
                    </label>
                    <label class="radio-inline">
                      <input type="radio" name="level" value="2" @if(!empty($result))@if($result->level == 2) checked @endif @endif> 高级
                    </label>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">课程时长</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" name="meta_value" class="form-control" value="@if(!empty($result)) {{$result->meta_value}} @else 0 @endif" />
                    <span class='help-block'>课程的总时长，默认为0,非视频文档默认都为0</span>
                </div>
                <div class="clearfix"></div>
            </div> 
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">课程价格</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" name="price" class="form-control" value="@if(!empty($result)) {{$result->price}} @else 0 @endif" />
                    <span class='help-block'>课程的总价格，消耗的积分</span>
                </div>
                <div class="clearfix"></div>
            </div> 
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" name="sort" class="form-control" value="@if(!empty($result)) {{$result->sort}} @else 0 @endif" />
                    <span class='help-block'>课程的排序，在前端列表展示的时候会用到，越大越靠前</span>
                </div>
                <div class="clearfix"></div>
            </div> 
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">讲师编号</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" name="author_id" class="form-control" value="@if(!empty($result)) {{$result->author_id}} @else 0 @endif" />
                    <span class='help-block'>如果讲师不为上传者的时候，可以在这里进行修改。默认为0</span>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">所属学院</label>
                <div class="col-sm-9 col-xs-12">
                    <input type="text" name="education" class="form-control" value="@if(!empty($result)) {{$result->education}} @endif" />
                    <span class='help-block'>课程所属学院，在首页会用到</span>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">首页推荐</label>
                <div class="col-sm-9 col-xs-12">
                    <label class="radio-inline">
                      <input type="radio" name="is_recommond" value="1" @if(!empty($result))  @if($result->is_recommond == 1) checked @endif @endif> 是
                    </label>
                    <label class="radio-inline">
                      <input type="radio" name="is_recommond"value="0" @if(!empty($result))  @if($result->is_recommond == 0) checked @endif @else checked @endif> 否
                    </label>
                    <span class='help-block'>选择是，将会在充电加油首页进行展示。</span>
                </div>
                <div class="clearfix"></div>
            </div> 
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">相关标签</label>
                <div class="col-sm-9 col-xs-12">
                    <div class="tagsinput-primary">
                        <input name="tagsinput" class="tagsinput" data-role="tagsinput" value="@if(!empty($newstag)) {{ $newstag }} @endif" />
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
    <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
    <input type="hidden" name="teachesid" value="@if(!empty($result)){{ $result->id }}@endif">  
    {!! csrf_field() !!}
    <div class="form-inline">
        <div class="form-group">
          <input type="hidden" name="stauts" value="1">
          <button type="button" class="btn btn-info" onclick="saveData('{{url('/admin/teaches/index')}}','teachesForm');" >
            <i class="icon-ok bigger-110"></i>
            Submit
          </button>
        </div>
        <div class="form-group col-xs-offset-1">
          <button type="reset" class="btn">
            <i class="icon-undo bigger-110"></i>
            Reset
          </button>
        </div>
    </div>
</form>
<script type="text/javascript">
<!--
var ue = UE.getEditor('description');
ue.ready(function() {
	ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.    
	ue.setContent('@if(!empty($result)) {!! $result->description !!} @endif');
});
	$(function(){
		/***图片上传****/
    	$("#thumburl").uploadify({
    	    'formData'     : {
    	        'fileField':'upfile',
    	        '_token':'{{ csrf_token() }}',
    	        'app':'teaches'
    	    },
    	    "width"           : 120,
    	    "height"          : 30,
    	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
    	    "fileObjName"     : "upfile",
    	    "buttonText"      : "上传图片",
    	    "uploader"        : '/admin/upload/uploadimg',
    	    'removeTimeout'	  : 1,
    	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
    	    'onUploadSuccess':function(file, data, response){
    	    	var data = eval('(' + data + ')');
    	        if (data.status == 'success') {
    
    	        	var html="<div style='width:90px; height:60px;float:left;'>"
    	            	+"<img src='"+data.attach+"' width='90' height='60' /><input type='hidden' name='thumb' value='"+data.attach_id+"' />"
    	            	+"<div class='clearfix'></div>"
    	            	+"</div>"
    	            $('#imgbox').html(html);
    	        }else{
    	            alert(data.msg);
    	            return false;
    	        }
    
    	    }
    
    	});
	});
//-->
</script>
@endsection